<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>04返回顶部案例</title>
</head>
    <style>
        .actGotop {
            position: fixed;
            bottom: 50px;
            right: 50px;
            width: 150px;
            height: 195px;
            display: none;
            z-index: 100;
        }
         .actGotop a, .actGotop a:link {
             width: 150px;
             height: 195px;
             display: inline-block;
             background: url(img/火箭.jpg) no-repeat;
             outline: none;
         }
        .actGotop a:hover {
            width: 150px;
            height: 195px;
            background: url(img/火箭.jpg) no-repest;
            outline: none;
        }
    </style>
<body>
   <div class="actGotop"><a href="#" title="Top"></a></div>
   <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
   <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
   <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>
   <p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p>

    <script src="../jquery-3.2.1.js"></script>
    <script>
        
        $(function(){
            // 当页面超过100px 小火箭显示 如果小于1000 小火箭隐藏
            $(window).scroll(function(){
                if($(window).scrollTop() >= 1000){
                    $(".actGotop").fadeIn(1000);
                }else {
                    $(".actGotop").fadeOut(1000);                    
                }
            });
            // 返回顶部
            $(".actGotop").click(function(){
                // body没有动画  ie不兼容
                $("html").animate({scrollTop:0}, 3000)
            })

        });
    
    
    </script>
</body>
</html>